package net.wofly.right.service.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import net.wofly.right.domain.Role;
import net.wofly.right.domain.User;
import net.wofly.right.domain.UserRole;
import net.wofly.right.repository.UserRoleRepository;
import net.wofly.right.service.IUserRoleService;

@Service("iUserRoleService")
@Transactional
public class UserRoleServiceImpl implements IUserRoleService {
    
    @Autowired
    UserRoleRepository userRoleRepository;
    
    @Override
    public UserRole save(UserRole entity) {
        return userRoleRepository.save(entity);
    }
    
    @Override
    public void delete(UserRole entity) {
    	userRoleRepository.delete(entity);
    }
    
    @Override
    public void delete(String key) {
    	userRoleRepository.delete(key);
    }
    
    @Override
    public UserRole findOne(String key) {
        return userRoleRepository.findOne(key);
    }
    
    @Override
    public List<UserRole> save(List<UserRole> entityList) {
        return (List<UserRole>) userRoleRepository.save(entityList);
    }
    
    @Override
    public List<UserRole> findByUserID(String userID) {
        return userRoleRepository.findByUserID(userID);
    }
    
    @Override
    public List<UserRole> findByRoleID(String roleID) {
        return userRoleRepository.findByRoleID(roleID);
    }
    
    @Override
    public List<User> findUsersByRoleID(String roleID) {
        return userRoleRepository.findUsersByRoleID(roleID);
    }
    
    @Override
    public List<User> findUsersByRoleIDs(List<String> roleIDs){
        return userRoleRepository.findUsersByRoleIDs(roleIDs);
    }
    
    @Override
    public List<Role> findRolesByUserID(String userID) {
        return userRoleRepository.findRolesByUserID(userID);
    }

    @Override
    public Page<User> findPageByRoleID(String roleID, Pageable pageable) {
        return userRoleRepository.findPageByRoleID(roleID, pageable);
    }
}
